package com.klb.service.catalog.impl;

import java.sql.Date;

import com.klb.dao.impl.ArticleDaoImpl;
import com.klb.model.BbsArticle;
import com.klb.service.catalog.PublishServiceCatalog;
import com.klb.tools.Tools;

/**
 * Created by fujia on 2016/6/15.
 */
public class PublishServiceCatalogImpl implements PublishServiceCatalog {
    private ArticleDaoImpl articleDao;

    public void setArticleDao(ArticleDaoImpl articleDao) {
        this.articleDao = articleDao;
    }


    @Override
    public boolean publishArticleIsSuccess(int blockId, int userId, String title, String text) {
        if (!Tools.objectIsNullOrNot(blockId) && !Tools.objectIsNullOrNot(userId)
                && !Tools.objectIsNullOrNot(title) && !Tools.objectIsNullOrNot(text)){
            BbsArticle article = new BbsArticle();

            java.util.Date nowDate = new java.util.Date();
            Date date = new Date(nowDate.getTime());

            article.setTitle(title);
            article.setText(text);
            article.setUserId(userId);
            article.setBlockId(blockId);
            article.setTags("");
            article.setDateAdded(date);

            if (this.articleDao.addQuery(article))
                return true;
        }
        return false;
    }


}
